/*
	Time test
		Fourteen tests (each a single instruction - measurements on a 33MHz 68LC040):
			add.w	d0,d1		~0.03s		= 1 clock
			adda.w	d0,a1		~0.06s		= 2 clocks
			sub.w	d0,d1		~0.03s		= 1 clock
			suba.w	d0,a1		~0.06s		= 2 clocks
			adda.w	a0,a1		~0.03s		= 1 clock
			suba.w	a0,a1		~0.06s		= 2 clocks
			adda.w	#16,a1		~0.03s		= 1 clock
			suba.w	#16,a1		~0.06s		= 2 clocks
			mulu.w	#2,d0		~0.33s		= 11 clocks
			muls.w	#2,d0		~0.33s		= 11 clocks
			divu.w	#2,d0		~0.33s		= 11 clocks
			divu.w	#2,d1		~0.85s		= 28 clocks
			mulu.l	#2,d0		~0.66s		= 22 clocks
			muls.l	#2,d0		~0.60s		= 20 clocks
			divu.l	#2,d0		~1.3s		= 45 clocks
		A tiny margin was rounded out (interupts were not turned off)
		The last four were run at least twice to make sure they were accurate
		What really baffled me was that instead of 14 and 16 in the Users Manual 
			for multiply unsigned and multiply, they came out 11.  Also, the
			difference between DIVU.W #2,d0 and DIVU.W #2,d1 is probably due
			to overflow- also, the Users Manual has 27 for the number of both.
*/

#include <Traps.h>

void startup(boolean display);
void startup(boolean display)
{
	UInt64		container_weight;

	register long		x, t2l, t2h, t1l, t1h;

	asm
	{
		trapf
		;Debugger
		move.l		#1000000,x
		jsr			([(_Microseconds-0xA000)<<2])
		move.l		d0,t1l
		move.l		a0,t1h
	}
	do {} while(--x);
	asm
	{
		jsr			([(_Microseconds-0xA000)<<2])
		move.l		d0,t2l
		move.l		a0,t2h
		sub.l		t1l,t2l
		subx.l		t1h,t2h
		move.l		t2h,container_weight(a6)
		move.l		t2l,container_weight+4(a6)
		trapf
		Debugger
		move.l		#1000000,x
		jsr			([(_Microseconds-0xA000)<<2])
		move.l		d0,t1l
		move.l		a0,t1h
	}
	do asm{add.w d0,d1} while(--x);
	asm
	{
		jsr			([(_Microseconds-0xA000)<<2])
		move.l		d0,t2l
		move.l		a0,t2h
		sub.l		t1l,t2l
		subx.l		t1h,t2h
		Debugger
		move.l		container_weight(a6),d0
		sub.l		container_weight+4(a6),t2l
		subx.l		d0,t2h
		trapf
		move.l		#1000000,x
		jsr			([(_Microseconds-0xA000)<<2])
		move.l		d0,t1l
		move.l		a0,t1h
	}
	do asm{adda.w d0,a1} while(--x);
	asm
	{
		jsr			([(_Microseconds-0xA000)<<2])
		move.l		d0,t2l
		move.l		a0,t2h
		sub.l		t1l,t2l
		subx.l		t1h,t2h
		Debugger
		move.l		container_weight(a6),d0
		sub.l		container_weight+4(a6),t2l
		subx.l		d0,t2h
		trapf
		move.l		#1000000,x
		jsr			([(_Microseconds-0xA000)<<2])
		move.l		d0,t1l
		move.l		a0,t1h
	}
	do asm{sub.w d0,d1} while(--x);
	asm
	{
		jsr			([(_Microseconds-0xA000)<<2])
		move.l		d0,t2l
		move.l		a0,t2h
		sub.l		t1l,t2l
		subx.l		t1h,t2h
		Debugger
		move.l		container_weight(a6),d0
		sub.l		container_weight+4(a6),t2l
		subx.l		d0,t2h
		trapf
		move.l		#1000000,x
		jsr			([(_Microseconds-0xA000)<<2])
		move.l		d0,t1l
		move.l		a0,t1h
	}
	do asm{suba.w d0,a1} while(--x);
	asm
	{
		jsr			([(_Microseconds-0xA000)<<2])
		move.l		d0,t2l
		move.l		a0,t2h
		sub.l		t1l,t2l
		subx.l		t1h,t2h
		Debugger
		move.l		container_weight(a6),d0
		sub.l		container_weight+4(a6),t2l
		subx.l		d0,t2h
		trapf
		Debugger
		move.l		#1000000,x
		jsr			([(_Microseconds-0xA000)<<2])
		move.l		d0,t1l
		move.l		a0,t1h
	}
	do asm{adda.w a0,a1} while(--x);
	asm
	{
		jsr			([(_Microseconds-0xA000)<<2])
		move.l		d0,t2l
		move.l		a0,t2h
		sub.l		t1l,t2l
		subx.l		t1h,t2h
		Debugger
		move.l		container_weight(a6),d0
		sub.l		container_weight+4(a6),t2l
		subx.l		d0,t2h
		move.l		#1000000,x
		jsr			([(_Microseconds-0xA000)<<2])
		move.l		d0,t1l
		move.l		a0,t1h
	}
	do asm{suba.w a0,a1} while(--x);
	asm
	{
		jsr			([(_Microseconds-0xA000)<<2])
		move.l		d0,t2l
		move.l		a0,t2h
		sub.l		t1l,t2l
		subx.l		t1h,t2h
		Debugger
		move.l		container_weight(a6),d0
		sub.l		container_weight+4(a6),t2l
		subx.l		d0,t2h
		move.l		#1000000,x
		jsr			([(_Microseconds-0xA000)<<2])
		move.l		d0,t1l
		move.l		a0,t1h
	}
	do asm{adda.w #16,a1} while(--x);
	asm
	{
		jsr			([(_Microseconds-0xA000)<<2])
		move.l		d0,t2l
		move.l		a0,t2h
		sub.l		t1l,t2l
		subx.l		t1h,t2h
		Debugger
		move.l		container_weight(a6),d0
		sub.l		container_weight+4(a6),t2l
		subx.l		d0,t2h
		move.l		#1000000,x
		jsr			([(_Microseconds-0xA000)<<2])
		move.l		d0,t1l
		move.l		a0,t1h
	}
	do asm{suba.w #16,a1} while(--x);
	asm
	{
		jsr			([(_Microseconds-0xA000)<<2])
		move.l		d0,t2l
		move.l		a0,t2h
		sub.l		t1l,t2l
		subx.l		t1h,t2h
		Debugger
		move.l		container_weight(a6),d0
		sub.l		container_weight+4(a6),t2l
		subx.l		d0,t2h
		move.l		#1000000,x
		jsr			([(_Microseconds-0xA000)<<2])
		move.l		d0,t1l
		move.l		a0,t1h
	}
	do asm{mulu.w #2,d0} while(--x);
	asm
	{
		jsr			([(_Microseconds-0xA000)<<2])
		move.l		d0,t2l
		move.l		a0,t2h
		sub.l		t1l,t2l
		subx.l		t1h,t2h
		Debugger
		move.l		container_weight(a6),d0
		sub.l		container_weight+4(a6),t2l
		subx.l		d0,t2h
		move.l		#1000000,x
		jsr			([(_Microseconds-0xA000)<<2])
		move.l		d0,t1l
		move.l		a0,t1h
	}
	do asm{muls.w #2,d0} while(--x);
	asm
	{
		jsr			([(_Microseconds-0xA000)<<2])
		move.l		d0,t2l
		move.l		a0,t2h
		sub.l		t1l,t2l
		subx.l		t1h,t2h
		Debugger
		move.l		container_weight(a6),d0
		sub.l		container_weight+4(a6),t2l
		subx.l		d0,t2h
		move.l		#1000000,x
		jsr			([(_Microseconds-0xA000)<<2])
		move.l		d0,t1l
		move.l		a0,t1h
	}
	do asm{divu.w #2,d1} while(--x);
	asm
	{
		jsr			([(_Microseconds-0xA000)<<2])
		move.l		d0,t2l
		move.l		a0,t2h
		sub.l		t1l,t2l
		subx.l		t1h,t2h
		Debugger
		move.l		container_weight(a6),d0
		sub.l		container_weight+4(a6),t2l
		subx.l		d0,t2h
		move.l		#1000000,x
		jsr			([(_Microseconds-0xA000)<<2])
		move.l		d0,t1l
		move.l		a0,t1h
	}
	do asm{mulu.l #2,d0} while(--x);
	asm
	{
		jsr			([(_Microseconds-0xA000)<<2])
		move.l		d0,t2l
		move.l		a0,t2h
		sub.l		t1l,t2l
		subx.l		t1h,t2h
		Debugger
		move.l		container_weight(a6),d0
		sub.l		container_weight+4(a6),t2l
		subx.l		d0,t2h
		move.l		#1000000,x
		jsr			([(_Microseconds-0xA000)<<2])
		move.l		d0,t1l
		move.l		a0,t1h
	}
	do asm{muls.l #2,d0:d1} while(--x);
	asm
	{
		jsr			([(_Microseconds-0xA000)<<2])
		move.l		d0,t2l
		move.l		a0,t2h
		sub.l		t1l,t2l
		subx.l		t1h,t2h
		Debugger
		move.l		container_weight(a6),d0
		sub.l		container_weight+4(a6),t2l
		subx.l		d0,t2h
		move.l		#1000000,x
		jsr			([(_Microseconds-0xA000)<<2])
		move.l		d0,t1l
		move.l		a0,t1h
	}
	do asm{divu.l #2,d1} while(--x);
	asm
	{
		jsr			([(_Microseconds-0xA000)<<2])
		move.l		d0,t2l
		move.l		a0,t2h
		sub.l		t1l,t2l
		subx.l		t1h,t2h
		Debugger
		move.l		container_weight(a6),d0
		sub.l		container_weight+4(a6),t2l
		subx.l		d0,t2h
	}
}
